package com.cater.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.DictionarydataDao;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.BaseService;

/**
 * 字典管理
 * 
 * @author ShenDong
 *
 */
@Service
public class DictionarydataServiceImpl implements BaseService<Dictionarydata, CommonQuery, Integer> {

	@Autowired
	private DictionarydataDao dao;

	@Override
	public PageResult<Dictionarydata> findPageResult(CommonQuery query) {
		PageResult<Dictionarydata> result = new PageResult<Dictionarydata>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<Dictionarydata> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<Dictionarydata> getAll() {
		return dao.getAll();
	}

	@Override
	public List<Dictionarydata> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(Dictionarydata t) {
		BaseEntity.getCreate(t);
		return dao.save(t);
	}

	@Override
	public void update(Dictionarydata t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(Integer.valueOf(id));

	}

	@Override
	public Dictionarydata getById(String id) {
		return dao.getById(Integer.valueOf(id));
	}

	public List<Dictionarydata> getDataByType(String type) {
		return dao.getDataByType(type);
	}

	@Override
	public String saves(Dictionarydata t) {
		return null;
	}

	public List<Dictionarydata> getGroupByType() {
		return dao.getGroupByType();
	}

	public Dictionarydata getByTypeValue(String values, String types) {
		return dao.getByTypeValue(values, types);
	}

	public String getTypeValue(String values, String types) {
		Dictionarydata ss = dao.getByTypeValue(values, types);
		return ss.getValueName();
	}
	
	/**
	 * @根据数据字典类型查询数据
	 * @param type
	 * @return
	 */
	public Dictionarydata getByType(String type) {
		return dao.getByType(type);
	}

}
